import pymysql

user = input('请输入用户名：').strip()
pwd = input('请输入密码：').strip()

# 建立连接
conn = pymysql.connect(
    # 路径
    host='localhost',
    # 端口
    port=3306,
    user='root',
    password='root',
    # 要访问的数据库
    db='python_study',
    # 编码格式
    charset='utf8'
)

# 获取游标
cursor = conn.cursor()

sql = f"select * from userinfo where user ='{user}' and pwd ='{pwd}'"
try:
    # 执行sql语句
    cursor.execute(sql)
    # 获取结果
    result = cursor.fetchone()
    print(result)
    if result:
        print('登录成功')
    else:
        print('登录失败')
finally:
    cursor.close()
    conn.close()
